import random

class Hero:
    hp = 0
    min_power = 0
    max_power = 0
    name = ""

    def getPower(self):
        """
        获取单次进攻值,在英雄最小和最大攻击力范围内随机
        :return:单次攻击力
        """
        power = random.randint(self.min_power, self.max_power)
        return power

    def UpdateEnemyHP(self, enemyClass, enemy_hp):
        """
        更新敌人的血量
        :param enemyClass: 敌人 类的实例化
        :param enemy_hp: 敌人实时血量
        """
        enemyClass.hp = enemy_hp

    def fight(self,enemyClass):
        power = self.getPower()
        self.hp = self.hp - enemyClass.getPower()
        enemy_hp = enemyClass.hp - power
        if enemy_hp >0 and self.hp >0:
            self.UpdateEnemyHP(enemyClass, enemy_hp)
            return "继续打"
        else:
            return {self.name:self.hp,enemyClass.name:enemy_hp}

class Timo(Hero):
    hp = 1000
    min_power = 15
    max_power = 60
    name = "Timo"

class Jinx(Hero):
    hp = 800
    min_power = 15
    max_power = 78
    name = "Jinx"

class HeroFactory:
    def create_hero(self, hero):
        if hero == "Timo":
            return Timo()
        elif hero == "Jinx":
            return Jinx()
        else:
            raise Exception("此英雄不在英雄工厂当中")

TIMO = HeroFactory().create_hero("Timo")
JINX = HeroFactory().create_hero("Jinx")

def main():
    while True:
        hero = TIMO
        enemy = JINX

        message = hero.fight(enemy)

        if "继续打" not in message:
            selfHP = message[hero.name]
            enemyHP = message[enemy.name]
            if selfHP > enemyHP:
                print(f"{hero.name}赢了,剩余血量:{selfHP}")
            else:
                print(f"{enemy.name}(敌人)赢了,剩余血量:{enemyHP}")
            break

if __name__ == "__main__":
    main()





